<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@include file="/include/common/loadingbackhead.jsp"%>
<%!
private class PageAction extends BaseAction{
	StringBuilderEx sql = null;
	ResultSet rs = null;
	
	protected void prepareActionEnv() throws Exception{
		sql = new StringBuilderEx();
	}
	
	//加載頁面默認數據
	protected boolean onLoadDefault() throws Exception{
		form.SetParamValue("org",utils.getDeptName());
		form.SetParamValue("orgtsn",utils.getHr003Tsn());
		return true ;
	}
	
	//Loading登陆验证
	protected void onLoadingValidate() throws Exception{
		if(form.isNullOrEmpty("orgtsn")){
			ret.setErrorInfo("生产部门不可以為空!");return;
		}
			
		if(form.isNullOrEmpty("hrnum")){
			ret.setErrorInfo("工人工號不可以為空!");return;
		}
			
		if(form.isNullOrEmpty("prosSn")){
			ret.setErrorInfo("工序號不可以為空!");return;
		}
			
		if(form.isNullOrEmpty("bill_no")){
			ret.setErrorInfo("工票號不可以為空");return;
		}
			
		if(form.isNullOrEmpty("qty")){
			ret.setErrorInfo("計件數不可以為空!");return;
		}
		
		if(!form.isIntGZ("qty")){
			ret.setErrorInfo("请输入大于0的整数!");return;
		}
	}
	
	// 执行Loading登陆
	protected void doLoading() throws Exception{
		PageResult pageResult = ret.getCallResult();
		String tsn = utils.getNewTsn("info5", "pan", "pan001");
		CrudDataEntity crud = form.getCrudDataEntity("info5","pan..pan001","sn","hrnum,prosSn,bill_no");
		crud.spsv("tsn", tsn);
		crud.spsv("hr003tsn", form.gpsv("orgtsn"));
		crud.spiv("qty", form.gpiv("qty"));
		crud.appendInserCols();
		int flag=crud.insert();
		
		if(flag == 1){
			//保存成功后 设置取消的参数,才会出现取消的按钮
			pageResult.getLoadingCancelParams().SetParamValue("tsn",tsn);
			
			//保存成功后 设置保存的参数,才会出现保存的按钮
			pageResult.getLoadingSaveParams().SetParamValue("tsn",tsn);
			
			//修改成功后 返回修改后的记录  主要 用来更新有些栏位验证前后不一致 如 00 取整后会变成 0
			pageResult.getLoadingrecord().SetParamValue("qty",form.gpiv("qty"));
		}else{
			pageResult.setErrorInfo("Loading 失败!");
		}
	}
	
	//Loading取消验证
	protected void onLoadingCancelValidate() throws Exception{
		
	}
	
	//执行Loading取消
	protected void doLoadingCancel() throws Exception{
		sql.Reset();
		sql.Append("delete from pan..pan001 where tsn = %1$s",form.gpsv("tsn"));
		utils.executeUpdate("info5",sql.toString());
	}
	
	//Loading保存验证/
	protected void onLoadingSaveValidate() throws Exception{
		if(!form.isIntGZ("qty")){
			ret.setErrorInfo("请输入大于0的整数!");return;
		}
	}
	
	//执行Loaing保存
	protected void doLoadingSave() throws Exception{
		PageResult pageResult = ret.getCallResult();
		sql.Reset();
		
		sql.Append("update pan..pan001 set ");
		sql.Append(" hrnum='%1$s'",form.gpsv("hrnum"));
		sql.Append(" ,prosSn='%1$s'",form.gpsv("prosSn"));
		sql.Append(" ,bill_no='%1$s'",form.gpsv("bill_no"));
		sql.Append(" ,qty='%1$s'",String.valueOf(form.gpiv("qty")));
		sql.Append(" where tsn=%1$s",form.gpiv("tsn"));
		int flag = utils.executeUpdate("info5",sql.toString());
		
		if(flag == 1){
			//修改成功后 返回修改后的记录  主要 用来更新有些栏位验证前后不一致 如 00 取整后会变成 0
			pageResult.getLoadingrecord().SetParamValue("qty",form.gpiv("qty"));
		}else{
			pageResult.setErrorInfo("修改失败,已删除!");
		}
	}
}
%>
<%@include file="/include/common/loadingbackend.jsp"%>